package com.neusoft.yuejian_01.model;

import com.neusoft.yuejian_01.base.BaseModel;
import com.neusoft.yuejian_01.javabean.ClubBean;
import com.neusoft.yuejian_01.javabean.ClubVideoBean;
import com.neusoft.yuejian_01.javabean.CourseBean;
import com.neusoft.yuejian_01.listener.RetrofitListener;
import com.neusoft.yuejian_01.service.ClubService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Administrator on 2017/9/29.
 */


    public class ClubModel extends BaseModel {

        //俱乐部列表
        public void  clublist(final RetrofitListener listener){
            this.flag = Const.ClubList;
            ClubService clubService = retrofit.create(ClubService.class);
            Call<List<ClubBean>> call = clubService.getClublist();
            Callback<List<ClubBean>> callback = new Callback<List<ClubBean>>() {
                @Override
                public void onResponse(Call<List<ClubBean>> call, Response<List<ClubBean>> response) {
                    List<ClubBean> clubBean = response.body();
                    listener.onSuccess(clubBean,flag);
                }
                @Override
                public void onFailure(Call<List<ClubBean>> call, Throwable t) {
                    listener.onFail();
                }
            };
            call.enqueue(callback);
        }
        //俱乐部详情
    public void clubDetail(String c_id,final RetrofitListener listener) {
        this.flag = Const.ClubDetail;
        ClubService clubService = retrofit.create(ClubService.class);
        Call call = clubService.getClubDetail(c_id);
        call.enqueue(new Callback<ClubBean>() {
            @Override
            public void onResponse(Call<ClubBean> call, Response<ClubBean> response) {
                ClubBean clubDetail=response.body();
                listener.onSuccess(clubDetail,flag);
            }
            @Override
            public void onFailure(Call<ClubBean> call, Throwable t) {
                listener.onFail();
            }
        });
    }
    //课程列表
    public void  courselist(String c_id,final RetrofitListener listener){
        this.flag = Const.ClubCourseList;
        ClubService clubService = retrofit.create(ClubService.class);
        Call<List<CourseBean>> call = clubService.getClubcourselist(c_id);
        Callback<List<CourseBean>> callback = new Callback<List<CourseBean>>() {
            @Override
            public void onResponse(Call<List<CourseBean>> call, Response<List<CourseBean>> response) {
                List<CourseBean> courseBean = response.body();
                listener.onSuccess(courseBean,flag);
            }
            @Override
            public void onFailure(Call<List<CourseBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }
    //俱乐部搜索
    public void  search(String c_name,final RetrofitListener listener){
        this.flag = Const.ClubList;
        ClubService clubService = retrofit.create(ClubService.class);
        Call<List<ClubBean>> call = clubService.getClubSearchlist(c_name);
        Callback<List<ClubBean>> callback = new Callback<List<ClubBean>>() {
            @Override
            public void onResponse(Call<List<ClubBean>> call, Response<List<ClubBean>> response) {
                List<ClubBean> clubBean = response.body();
                listener.onSuccess(clubBean,flag);
            }
            @Override
            public void onFailure(Call<List<ClubBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }
    //视频列表
    public void  videolist(String c_id,final RetrofitListener listener){
        this.flag = Const.ClubVideoList;
        ClubService clubService = retrofit.create(ClubService.class);
        Call<List<ClubVideoBean>> call = clubService.getClubvideolist(c_id);
        Callback<List<ClubVideoBean>> callback = new Callback<List<ClubVideoBean>>() {
            @Override
            public void onResponse(Call<List<ClubVideoBean>> call, Response<List<ClubVideoBean>> response) {
                List<ClubVideoBean> clubVideoBean = response.body();
                listener.onSuccess(clubVideoBean,flag);
            }
            @Override
            public void onFailure(Call<List<ClubVideoBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }
    }





